package Java8实战.Lambda实战._1_Lambda方法引用_传递代码;

import Java8实战.Lambda实战.Apple;

import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;

public class _1_Lambda方法引用_传递代码 {

    public static void main(String[] args) {
        List<Apple> appleList = Arrays.asList(
                new Apple("red",150),
                new Apple("green",123),
                new Apple("green",450)
        );

        appleList.sort(new AppleComparator());

        printByConsumer(appleList, (Apple apple) -> System.out.println("颜色为：" +apple.getColor()  + "，重量为：" + apple.getWeight()));
    }

    public static <T> void printByConsumer(List<T> list, Consumer<T> consumer){
        for (T t : list){
            consumer.accept(t);
        }
    }
}
